App Service (1 / 97): As an Azure Cloud Engineer, your company needs you to streamline the deployment process of their web applications. To help achieve this, they've asked you to automate the process using a bash script.
Here's your mission: the script needs to set up an environment in Azure that pulls a Docker container named companywebapp:latest from your company's private registry and deploys it to an Azure App Service in the East US region.
The resources that need to be created include a resource group (tagged with deploy-linux-docker-app-only.sh), an app service plan, and a web app. Can you write a script that fulfills these requirements?
let "randomIdentifier=$RANDOM*$RANDOM"
resourceGroup="msdocs-app-service-rg-$randomIdentifier"
appServicePlan="msdocs-app-service-plan-$randomIdentifier"
webapp="msdocs-web-app-$randomIdentifier"
registryUrl="https://yourCompanyRegistry.azurecr.io"
# Code here
Answer:
let "randomIdentifier=$RANDOM*$RANDOM"
resourceGroup="msdocs-app-service-rg-$randomIdentifier"
appServicePlan="msdocs-app-service-plan-$randomIdentifier"
webapp="msdocs-web-app-$randomIdentifier"
registryUrl="https://yourCompanyRegistry.azurecr.io"
location="East US"
tag="deploy-linux-docker-app-only.sh"
dockerHubContainerPath="simplewebapp:latest"
# Create a resource group.
az group create --name $resourceGroup --location "$location" --tag $tag
# Create an App Service plan
az appservice plan create --name $appServicePlan --resource-group $resourceGroup
# Create a web app.
az webapp create --name $webapp --resource-group $resourceGroup --plan $appServicePlan --runtime "NODE|14-lts"
# Configure the web app to use the Docker container image from your company's custom registry
az webapp config container set --name $webapp --resource-group $resourceGroup --docker-custom-image-name $dockerHubContainerPath --docker-registry-server-url $registryUrl
Note: --docker-registry-server-url is not needed if the image is on DockerHub